// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   TransferRight.java

package include.right;

import include.nseer_db.nseer_db_backup;
import java.io.PrintStream;
import java.sql.ResultSet;
import javax.servlet.ServletContext;

public class TransferRight
{

	private String treetemp;
	private ServletContext dbApplication;

	public TransferRight(ServletContext dbApplication)
	{
		this.dbApplication = dbApplication;
	}

	public void run(String mod, String dbase, String human_ID)
	{
		String treeadd = (new StringBuilder(String.valueOf(mod))).append("_tree").toString();
		String treeAright = (new StringBuilder(String.valueOf(mod))).append("_allright").toString();
		treetemp = (new StringBuilder(String.valueOf(mod))).append("_view").toString();
		try
		{
			nseer_db_backup demo = new nseer_db_backup(dbApplication);
			nseer_db_backup demo1 = new nseer_db_backup(dbApplication);
			nseer_db_backup demo2 = new nseer_db_backup(dbApplication);
			if (demo.conn(dbase) && demo1.conn(dbase) && demo2.conn(dbase))
			{
				String sql66 = (new StringBuilder("delete from ")).append(treetemp).append(" where human_ID='").append(human_ID).append("'").toString();
				demo.executeUpdate(sql66);
				ResultSet rs22 = demo.executeQuery((new StringBuilder("select * from ")).append(treetemp).append(" where module_name='all'").toString());
				if (!rs22.next())
				{
					String sql6 = (new StringBuilder("insert into ")).append(treetemp).append("(MODULE_NAME,CATEGORY_ID,PARENT_CATEGORY_ID) values('all','0','-1')").toString();
					demo.executeUpdate(sql6);
				}
				String main_id = "";
				String second_id = "";
				String abc30 = (new StringBuilder("select * from ")).append(treeAright).append(" where human_ID='").append(human_ID).append("' order by id").toString();
				ResultSet rs30 = demo.executeQuery(abc30);
				int i = 1;
				int j = 100;
				int k = 1000;
				int ii = 0;
				int jj = 0;
				while (rs30.next()) 
				{
					String abc = (new StringBuilder("select * from ")).append(treeadd).append(" where main='").append(rs30.getString("main")).append("' and secondary='").append(rs30.getString("secondary")).append("' and third='").append(rs30.getString("third")).append("'").toString();
					for (ResultSet rss = demo2.executeQuery(abc); rss.next();)
					{
						String sqq = (new StringBuilder("select * from ")).append(treetemp).append(" where module_name='").append(rs30.getString("main")).append("' and human_ID='").append(rs30.getString("HUMAN_ID")).append("' and parent_category_id='0'").toString();
						ResultSet rsq = demo1.executeQuery(sqq);
						if (!rsq.next())
						{
							String sqla = (new StringBuilder("insert into ")).append(treetemp).append("(MODULE_NAME,category_id,PARENT_CATEGORY_ID,HREFLINK,HUMAN_ID,NAME) values('").append(rss.getString("main")).append("','").append(i).append("','0','").append(rss.getString("MAINURL").substring(6)).append("','").append(rs30.getString("HUMAN_ID")).append("','").append(rs30.getString("NAME")).append("')").toString();
							demo1.executeUpdate(sqla);
							main_id = (new StringBuilder(String.valueOf(i))).toString();
							ii = i;
							i++;
						} else
						{
							main_id = rsq.getString("category_id");
						}
						sqq = (new StringBuilder("select * from ")).append(treetemp).append(" where module_name='").append(rs30.getString("secondary")).append("' and human_ID='").append(rs30.getString("HUMAN_ID")).append("' and parent_category_id='").append(main_id).append("' and category_id<=1000").toString();
						rsq = demo1.executeQuery(sqq);
						if (!rsq.next())
						{
							String sqla = (new StringBuilder("insert into ")).append(treetemp).append("(MODULE_NAME,category_id,PARENT_CATEGORY_ID,HREFLINK,HUMAN_ID,NAME) values('").append(rss.getString("secondary")).append("','").append(j).append("','").append(ii).append("','").append(rss.getString("secondURL").substring(6)).append("','").append(rs30.getString("HUMAN_ID")).append("','").append(rs30.getString("NAME")).append("')").toString();
							demo1.executeUpdate(sqla);
							second_id = (new StringBuilder(String.valueOf(j))).toString();
							jj = j;
							j++;
						} else
						{
							second_id = rsq.getString("category_id");
						}
						if (!rs30.getString("third").equals(""))
						{
							sqq = (new StringBuilder("select * from ")).append(treetemp).append(" where module_name='").append(rs30.getString("third")).append("' and human_ID='").append(rs30.getString("HUMAN_ID")).append("' and parent_category_id='").append(second_id).append("' and category_id>=1000").toString();
							rsq = demo1.executeQuery(sqq);
							if (!rsq.next())
							{
								String sqla = (new StringBuilder("insert into ")).append(treetemp).append("(MODULE_NAME,category_id,PARENT_CATEGORY_ID,HREFLINK,HUMAN_ID,NAME) values('").append(rss.getString("third")).append("','").append(k).append("','").append(jj).append("','").append(rss.getString("thirdURL").substring(6)).append("','").append(rs30.getString("HUMAN_ID")).append("','").append(rs30.getString("NAME")).append("')").toString();
								demo1.executeUpdate(sqla);
								k++;
							}
						}
					}

				}
				demo.close();
				demo1.close();
				demo2.close();
			} else
			{
				System.out.println("i am sorry");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
